package com.sz.admin.ai.factory.chatFactory;

import com.sz.admin.ai.factory.chatFactory.entity.ChatPlatformEnum;
import com.sz.admin.ai.factory.chatFactory.handler.ChatHandler;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @描述: 对话模型Handler工厂
 * @Author: TangYuan
 * @Date: 2025/2/24 15:06
 */
@Component
public class ChatHandlerFactory implements InitializingBean {
    
    @Resource
    private List<ChatHandler> chatHandlerList;

    private final Map<ChatPlatformEnum, ChatHandler> handlerMap = new HashMap<>();

    public ChatHandler getHandler(String platformName) {
        ChatPlatformEnum chatPlatformEnum = ChatPlatformEnum.getEnumByPlatformName(platformName);
        return handlerMap.get(chatPlatformEnum);
    }

    @Override
    public void afterPropertiesSet() {
        for (ChatHandler chatHandler : chatHandlerList) {
            handlerMap.put(chatHandler.getChatPlatformEnum(), chatHandler);
        }
    }
}